package com.laguille.games.monopoly.commons.event;

import org.apache.commons.lang.Validate;

import com.laguille.games.monopoly.commons.player.Player;

/**
 * Event emitted when a player joins the game.
 *
 */
public class NewPlayerEvent extends Event {

	private final Player newPlayer;
	
	public NewPlayerEvent(Player newPlayer)  {
		Validate.notNull(newPlayer);
		this.newPlayer= newPlayer;
	}

	/**
	 * @return the newPlayer
	 */
	public Player getNewPlayer() {
		return newPlayer;
	}


	/* (non-Javadoc)
	 * @see java.lang.Object#hashCode()
	 */
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((newPlayer == null) ? 0 : newPlayer.hashCode());
		return result;
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#equals(java.lang.Object)
	 */
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		NewPlayerEvent other = (NewPlayerEvent) obj;
		if (newPlayer == null) {
			if (other.newPlayer != null)
				return false;
		} else if (!newPlayer.equals(other.newPlayer))
			return false;
		return true;
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString() {
		return "NewPlayerEvent [newPlayer=" + newPlayer + "]";
	}

}
